/*get value from frame, the frame include the report file*/
var titlArr = new Array();		// ��������
var xStrArr = new Array();		//
var yValArr = new Array();		//
var ro_flag = false;			//�Ƿ�������
var xStrName = "";
/*default chart type, 3 stand for pole figure*/
var DEFAULTCT = 3;
var GchartType = DEFAULTCT;

/*
    function: draw chart according the parameter of charType
*/
function drawChart(chartType)
{
    getValue();
    if(yValArr == null )
    {
        return;
    }    
    if(yValArr.length <= 0)
    {
        return ;
    }
	chartDiv.innerHTML="";
	if (titlArr.length>0 && xStrArr.length>0 && yValArr.length>0)
    {
       //折线图
    	if (chartType==1)
        {
           // alert(chartType +"==折线图");
            GchartType = 1;
    		chartDiv.innerHTML=drawpoly(xStrArr,yValArr,titlArr);
        }      
        //饼图
    	if (chartType==2) 
        {
           // alert(chartType +"==饼图");
            GchartType = 2;
    		chartDiv.innerHTML=drawpie(xStrArr,yValArr,titlArr);		
        }      
        //柱图
    	if (chartType==3)
        {   
           // alert(chartType +"==柱图");        
            GchartType = 3;
    		chartDiv.innerHTML=drawpole(xStrArr,yValArr,titlArr);
        }     
	}
}


//图标所包含的指标名称
/**/
var chartIndex = '';

//标题
var chartTitle="合同额";

//图形类型
var chartType =2;

//数据扩展方向
var chartExtendDire="Y";

//数值度量单位
var chartValueUnit="元";

//起始位置
var chartExcelBlock="5,2";

//数值对应单位起始位置
var chartExcelBlockCom="5,1";

//指标类型
var chartIndexType = "年计划";


//从页面中获取参数以及数据
function getValue()
{  
    chartTitle = document.getElementById("Titile").value ;
    chartType = document.getElementById("ChartType").value ;
    chartExtendDire = document.getElementById("ExtendDire").value ;
    chartValueUnit = document.getElementById("ValueUnit").value ;
    chartExcelBlock = document.getElementById("ExcelBlock").value ;
    chartExcelBlockCom = document.getElementById("ExcelBlockCom").value ;
    chartIndexType = document.getElementById("IndexName").value ;
    
    //获取标题    
    chartIndex = chartTitle;
   
    //设置图标标题
    document.getElementById("chartTitle").innerHTML = "<font size = 3 ><b>" + chartIndex + "</b></font>"; 
         
    titlArr.length=0;
    xStrArr.length=0;
    yValArr.length=0;
    
    //获取页面table数据
    titlArr = getValueS(chartExcelBlockCom, chartExtendDire);
    
    for(i = 0; i < titlArr.length; i++)
    {
        var tmStr = " " + titlArr[i];
        var tmStrArray = tmStr.split(" ");
        tmStr = "";
        for(j = 0; j < tmStrArray.length; j++)
        {
            tmStr = tmStr + tmStrArray[j];
        }
        tmStr.replace(/(^\s*)|(\s*$)/g, "");
        titlArr[i] = tmStr;   
    }
    
    var tmDX;
    var tmDY;
    var tmDXY = chartExcelBlock.split(",");
    tmDX = parseInt(tmDXY[0]);
    tmDY = parseInt(tmDXY[1]);
  
    for(h = 0; h > -1; h++)
    {
        var tmX1 = 0;
        var tmY1 = 0;
        if("1" == chartExtendDire)
        {
            tmX1 = tmDX + parseInt(h);
            tmY1 = tmDY;
        }
        else if("2" == chartExtendDire)
        {
            tmX1 = tmDX;
            tmY1 = tmDY + parseInt(h);            
        }
        
        var tmArr = getValueS("" + tmX1 + "," + tmY1, chartExtendDire);
        if (tmArr.length == 0) 
        {
            break;
        }
        for(i = 0; i < tmArr.length; i++)
        {
            if( h == 0)
            {
                var tmArr2 = new Array();
                  
                if(tmArr[i] != "" )
                {
                    tmArr2[0] = tmArr[i].split("%")[0];
                }
                else
                {
                    tmArr2[0] = 0;
                }
                yValArr[i] =  tmArr2;               
            }
           //获取指标的值
            else
            {                        
                //if(tmArr[i] > 0)
                if(tmArr[i] != "")
                {                   
                    //去掉table中数据项的%
                    tmArr[i]=tmArr[i].split("%")[0];       
                    yValArr[i][h] = tmArr[i];                          
                }
                else
                {                        
                   yValArr[i][h] = 0;               
                }                         
            }
        }  
     } 

    var tmX;
    var tmY;
    var tmXY = chartIndexType.split(",");
    tmX = parseInt(tmXY[0]);
    tmY = parseInt(tmXY[1]);
    
    //指标类型
    xStrName = getValueHtml(tmX,tmY);
    if("1" == chartExtendDire)
    {
        tmX += 1;
        xStrArr = getValueS(""+tmX+","+tmY, 2);
    }
    else if("2" == chartExtendDire )
    {
        tmY += 1;
        xStrArr = getValueS(""+tmX+","+tmY, 1);       
    }
    
}

